<?php
if(!defined('IN_XLR')) {
	exit('Access Denied');
}

//约练列表
function api_invite_list($apiReq){
	global $_SGLOBAL, $_CONFIG;
	
	$page_no = 1;
	if(isset($apiReq['page_no'])){
		$page_no = $apiReq['page_no'];
	}
	$pagesize = 10 ;
  	$rs_number = ($page_no - 1) * $pagesize ;

    //param 地区id aread_id / 运动类型 stype / 悬赏模式 reward_type / 约男或女 request_type / 水平 level_type 
    $area_id = '';
	if(isset($apiReq['area_id'])){
       $area_id = $apiReq['area_id'];
	}
 
    $wherestr = ' ';
	if(isset($apiReq['stype'])){
  	    $wherestr = $wherestr.' and a.stype='.$apiReq['stype'] ; 
	}
	if(isset($apiReq['reward_type'])){
  	    $wherestr = $wherestr.' and a.reward_type='.$apiReq['reward_type'] ; 
	}
	if(isset($apiReq['request_type'])){
  	    $wherestr = $wherestr.' and a.request_type='.$apiReq['request_type'] ; 
	}
	if(isset($apiReq['level_type'])){
  	    $wherestr = $wherestr.' and a.level_type='.$apiReq['level_type'] ; 
	}

	$orderstr = ' order by a.id desc';
	if(isset($apiReq['order_type'])){
       $order_type = $apiReq['order_type'];
       if($order_type=='coin'){
			$orderstr = ' order by a.coins desc';
       }
       if($order_type=='lbs'){

       }
	}

 	$sql = "select a.*,a.id as invite_id,b.nickname,b.thumb,b.height,b.sex from invite a,member b where a.status=1 and a.member_id=b.id $wherestr $orderstr limit $rs_number,$pagesize";
	$inviteList = get_db()->get_results($sql);

	$count = count($inviteList);
  
	//输出
	$apiOut["returncode"] = "0";
 	$apiOut["apiReq"] = $apiReq;
 	$apiOut["invite_list"] = $inviteList;
 	$apiOut["count"] = $count;
 	$apiOut["page_no"] = $page_no;
 	$apiOut["stype"] = 'all';

	return $apiOut;
}
